#pragma once

#include <QObject>

namespace  qhttp::server {
	class QHttpServer;
	class QHttpRequest;
	class QHttpResponse;
}
class QThread;

typedef std::function<int(const QString& path, const QByteArray& req, QByteArray& ans)> ServerFun;

class HttpServer : public QObject
{
	Q_OBJECT
public:
	HttpServer(QObject* parent);
	~HttpServer();

	int StartSever(const QString& ip, int port);
	int ReStartSever();
	bool IsListening();
	bool RegisterServerFunc(ServerFun fun);
signals:
	void ReceiveWCSMsg(int cmd, QByteArray& data);

private:
	void ParseHttpdata(qhttp::server::QHttpRequest* req, qhttp::server::QHttpResponse* rep);
private slots:
	void DealWitHttpInfo(qhttp::server::QHttpRequest* req, qhttp::server::QHttpResponse* rep);

private:
	ServerFun m_callBack;
	qhttp::server::QHttpServer* m_http = nullptr;
	int m_port = 0;
	QString m_ip;
	QThread* m_th = nullptr;
};
